'use strict';
 
const Controller = require('egg').Controller;
 
class UserController extends Controller {
    //post  创建用户
    async  create () {
        const { ctx } = this;
        ctx.body=await ctx.service.user.create(ctx.request.body);
    }
    //del  删除用户 
    async destroy() {
        const { ctx} = this;
        const userId = +ctx.params.id;
        ctx.body = await ctx.service.user.del(userId);
      }
     //post 修改用户
     async update() {
      const {
        ctx,
      } = this;
      const id = +ctx.params.id;
      const user = ctx.request.body;
      ctx.body = await ctx.service.user.update({
        id,
        user,
      });
    }
    //用户登陆（我们传入用户名，密码）
    async login() {
      const {
        ctx,
      } = this;
      const {
        username,
        password,
      } = ctx.request.body;
      ctx.body = await ctx.service.user.login({
        username,
        password,
      });
    }
    //查找用户
    async find() {
      const {
        ctx,
      } = this;
      const id = +ctx.params.id;
      ctx.body = await ctx.service.user.find(id);
    }
}

 
module.exports = UserController;
